package ihm.model;

import java.util.List;

import uccimpl.DebtService;

import domain.Debt;

public class DebtModel implements Model {
	
	private List<Debt> debts;
	private DebtService debtService = DebtService.getInstance();
	
	public DebtModel() {
		this.setDebts(debtService.listAll());
	}

	public List<Debt> getDebts() {
		return debts;
	}

	public void setDebts(List<Debt> debts) {
		this.debts = debts;
	}
	
	public void addDebt(Debt debt) {
		this.debts.add(debt);
	}
	
	public void updateDebt(Debt debt) {
		for (Debt currDebt : debts) {
			if (currDebt.getId() == debt.getId()) {
				debts.remove(currDebt);
				debts.add(debt);
				break;
			}
		}
	}
	
	public void removeDebt(Debt debt) {
		for (Debt currDebt : debts) {
			if (currDebt.getId() == debt.getId()) {
				debts.remove(currDebt);
				break;
			}
		}
	}

}
